package com.fqgj.sentry.policy.engine.eval.script

import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ImportCustomizer
import org.codehaus.groovy.control.customizers.SecureASTCustomizer

class ScriptEvalReady {

    static CompilerConfiguration getConfig() {
        def config = new CompilerConfiguration()

        def secure = new SecureASTCustomizer()
        secure.starImportsBlacklist = ['java.io.*']
        secure.indirectImportCheckEnabled = true

        def importCustomizer = new ImportCustomizer()
        importCustomizer.addStaticStars('com.fqgj.sentry.policy.engine.eval.script.MathUtils')
        importCustomizer.addStaticStars('com.fqgj.sentry.policy.engine.eval.script.OtherUtils')
        importCustomizer.addStaticStars('com.fqgj.sentry.policy.engine.eval.triple.TripleServiceData')

        config.addCompilationCustomizers(secure, importCustomizer)
        config
    }

    static Binding getBinding(Map normalVar) {

        Map variables = [
                *: normalVar
//                *: jsonForParsing.collectEntries { key, value -> [(key): parser.parseText(value)] }

        ]
        new Binding(variables)
    }


}
